package drone.basis.util ;

import net.sourceforge.pinyin4j.PinyinHelper ;

public class PinyinUtil
{

	public static String head (
			String hanzi
	)
	{
		String result = null ;
		if ( null != hanzi && ! "".equals ( hanzi ) )
		{
			char [ ] charArray = hanzi.toCharArray ( ) ;
			StringBuffer sb = new StringBuffer ( ) ;
			for ( char ch : charArray )
			{
				String [ ] stringArray = PinyinHelper.toHanyuPinyinStringArray ( ch ) ;
				if ( null != stringArray )
				{
					sb.append ( stringArray [ 0 ].charAt ( 0 ) ) ;
				}
			}

			if ( sb.length ( ) > 0 )
			{
				result = sb.toString ( ).toUpperCase ( ) ;
			}

		}
		return result ;

	}

	public static String body (
			String hanzi
	)
	{
		String result = null ;
		if ( null != hanzi && ! "".equals ( hanzi ) )
		{
			char [ ] charArray = hanzi.toCharArray ( ) ;
			StringBuffer sb = new StringBuffer ( ) ;
			for ( char ch : charArray )
			{

				String [ ] stringArray = PinyinHelper.toHanyuPinyinStringArray ( ch ) ;
				if ( null != stringArray )
				{
					sb.append ( stringArray [ 0 ].replaceAll ( "\\d" , "" ) ) ;
				}

			}

			if ( sb.length ( ) > 0 )
			{
				result = sb.toString ( ) ;
			}

		}
		return result ;

	}

	public static void main (
			String [ ] args
	)
	{

		System.out.println ( PinyinUtil.head ( "袁素芳" ) ) ;

		System.out.println ( PinyinUtil.body ( "袁素芳" ) ) ;

	}

}
